package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WhiteAffairMapper;
import com.ruoyi.system.domain.WhiteAffair;
import com.ruoyi.system.service.IWhiteAffairService;

/**
 * 白事Service业务层处理
 *
 * @author ruoyi
 * @date 2022-04-25
 */
@Service
public class WhiteAffairServiceImpl implements IWhiteAffairService {
    @Autowired
    private WhiteAffairMapper whiteAffairMapper;

    /**
     * 查询白事
     *
     * @param id 白事主键
     * @return 白事
     */
    @Override
    public WhiteAffair selectWhiteAffairById(String id) {
        return whiteAffairMapper.selectWhiteAffairById(id);
    }

    /**
     * 查询白事列表
     *
     * @param whiteAffair 白事
     * @return 白事
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<WhiteAffair> selectWhiteAffairList(WhiteAffair whiteAffair, String begin, String end) {
        Date begin1 = null, end1 = null;
        if (StringUtils.isNotEmpty(begin) && StringUtils.isNotEmpty(end)) {
            begin1 = new Date(Long.parseLong(String.valueOf(begin)));
            end1 = new Date(Long.parseLong(String.valueOf(end)));
            whiteAffair.setBeginDate(begin1);
            whiteAffair.setEndDate(end1);
        }
        return whiteAffairMapper.selectWhiteAffairList(whiteAffair);
    }

    /**
     * 新增白事
     *
     * @param whiteAffair 白事
     * @return 结果
     */
    @Override
    public int insertWhiteAffair(WhiteAffair whiteAffair) {
        if (StringUtils.isNotEmpty(whiteAffair.getAffairTime())) {
            String d1 = whiteAffair.getAffairTime().split("至")[0];
            if (StringUtils.isNotEmpty(d1)) {
                whiteAffair.setBeginDate(DateUtils.StrToDate(d1));
            }
            String d2 = whiteAffair.getAffairTime().split("至")[1];
            if (StringUtils.isNotEmpty(d1)) {
                whiteAffair.setEndDate(DateUtils.StrToDate(d2));
            }

        }
        return whiteAffairMapper.insertWhiteAffair(whiteAffair);
    }

    /**
     * 修改白事
     *
     * @param whiteAffair 白事
     * @return 结果
     */
    @Override
    public int updateWhiteAffair(WhiteAffair whiteAffair) {
        return whiteAffairMapper.updateWhiteAffair(whiteAffair);
    }

    /**
     * 批量删除白事
     *
     * @param ids 需要删除的白事主键
     * @return 结果
     */
    @Override
    public int deleteWhiteAffairByIds(String[] ids) {
        return whiteAffairMapper.deleteWhiteAffairByIds(ids);
    }

    /**
     * 删除白事信息
     *
     * @param id 白事主键
     * @return 结果
     */
    @Override
    public int deleteWhiteAffairById(String id) {
        return whiteAffairMapper.deleteWhiteAffairById(id);
    }
}
